<template>
    <div style="display: flex;line-height: 60px;">
        <div style="margin-top: 8px; ">
            <i :class="icon" style="font-size: 20px; cursor:pointer;" @click="collapse"></i>
        </div>
        <div style="flex: 1;text-align: center;font-size: 34px;">
                <span>欢迎来到餐馆管理系统</span>
        </div>
    <el-dropdown>
        <span>{{user.name}}</span>
        <i class="el-icon-arrow-down" style="margin-left: 8px"></i>
        <el-dropdown-menu slot="dropdown">
            <el-dropdown-item @click.native="toUser">个人中心</el-dropdown-item>
            <el-dropdown-item @click.native="Logout">退出登录</el-dropdown-item>

        </el-dropdown-menu>
    </el-dropdown>

    </div>
</template>

<script>
    export default {
        name: "Header",
        props:{
            icon:String
        },
        data(){
            return{
                user:JSON.parse(sessionStorage.getItem('CurUser'))
            }
        }

        ,
        methods:{

            toUser(){
                this.$router.push('/Home')
            },
            Logout(){
                this.$confirm('你确定要退出登录吗?','提示',{
                    confirmButtonText:'确认退出',//退出确认
                    type:"warning",
                    center:true,//文字居中显示
                  /*  showCancelButton:false,//不显示取消按钮
                    showClose:false,//是否显示右上角的X
                    closeOnClickModal:false,//是否可以点击空白处关闭弹窗
*/
                }).then(()=>{
                    this.$message({
                        type:'success',
                        message:'退出登录成功'
                    })

                    this.$router.push('/');
                    sessionStorage.clear();
                }).catch(()=>{
                    this.$message({
                        type:'info',
                        message:'已取消退出登录!'
                    })
                })



            },
            collapse(){//点击提交跳转至首页调用doCollapse方法
                this.$emit('doCollapse')
            }
        },created() {
            this.$router.push("/Home")
        }
    }
</script>

<style scoped>

</style>